const express = require('express')

let app = express()
app.use(express.static('.'))
app.use(express.urlencoded({
     extended:false
}))
app.use(express.json())

app.get('/',(req,res)=>{
    res.json('hi')
})

let data={
    sno:'07200822',
    name:'',
    gender:1,
    skill:[
        {
            name:'HTML',
            count:0
        },
        {
            name:'CSS',
            count:0
        },
        {
            name:'Javascript',
            count:0
        },
        {
            name:'miniprogram',
            count:0
        },
        {
            name:'MySQL',
            count:0
        },
        {
            name:'photoshop',
            count:0
        }

    ],
    satisfaction:0,
    opinion:'',
    count:0
}
app.get('/sampledata',(req,res)=>{
    res.json(data)
})
app.post('/sampledata',(req,res)=>{
    console.log(req.body)
    data.skill.forEach(v=>{
        req.body.skill.indexOf(v.name)>-1?v.count++:''
    })
   // data.satisfaction = (data.satisfaction*data.count+req.body.satisfaction)/(data.count+1)
   data.satisfaction = req.body.satisfaction
    data.count++
    data.name=req.body.name
    data.opinion+=req.body.name+':'+req.body.opinion +'\n'
    res.json(data)
})
app.listen(9999)

